package com.sf.fy.uav.good.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sf.fy.uav.common.response.order.task.GoodsResponse;
import com.sf.fy.uav.common.response.order.task.GoodsTypeResponse;
import com.sf.fy.uav.common.utils.BeanUtil;
import com.sf.fy.uav.good.entity.CityGoodsType;
import com.sf.fy.uav.good.entity.GoodsType;
import com.sf.fy.uav.good.mapper.CityGoodsTypeMapper;
import com.sf.fy.uav.good.mapper.GoodsTypeMapper;
import com.sf.fy.uav.good.service.IGoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 物资类型 服务实现类
 * </p>
 *
 * @author LTQ
 * @since 2023-04-13
 */
@Service
public class GoodsTypeServiceImpl extends ServiceImpl<GoodsTypeMapper, GoodsType> implements IGoodsTypeService {

    @Autowired
    private GoodsTypeMapper goodsTypeMapper;

    @Autowired
    private CityGoodsTypeMapper cityGoodsTypeMapper;

    @Override
    public List<GoodsTypeResponse> getGoodsType() {
        QueryWrapper<GoodsType> goodsTypeQueryWrapper = new QueryWrapper<>();
        goodsTypeQueryWrapper.eq("enable", true);
        goodsTypeQueryWrapper.orderByAsc("display_order");
        List<GoodsType> goodsTypes = goodsTypeMapper.selectList(goodsTypeQueryWrapper);
        List<GoodsTypeResponse> goodsTypeResponses = BeanUtil.copyProperties(goodsTypes, GoodsTypeResponse.class);
        return goodsTypeResponses;
    }

    @Override
    public List<GoodsTypeResponse> getCityGoodsType() {
        QueryWrapper<CityGoodsType> cityGoodsTypeQueryWrapper = new QueryWrapper<>();
        cityGoodsTypeQueryWrapper.eq("enable", true);
        cityGoodsTypeQueryWrapper.orderByAsc("display_order");
        List<CityGoodsType> cityGoodsTypes = cityGoodsTypeMapper.selectList(cityGoodsTypeQueryWrapper);
        List<GoodsTypeResponse> goodsTypeResponses = BeanUtil.copyProperties(cityGoodsTypes, GoodsTypeResponse.class);
        return goodsTypeResponses;
    }

    @Override
    public GoodsTypeResponse getById(String id) {
        CityGoodsType cityGoodsType = cityGoodsTypeMapper.selectById(id);
        return BeanUtil.copyProperties(cityGoodsType, GoodsTypeResponse.class);
    }
}
